﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global.css"/>
    <link type="text/css" rel="stylesheet" media="all" href="../styles/global_color.css"/>
    <script language="javascript" type="text/javascript">
        //显示角色详细信息
        function showDetail(flag, a) {
            var detailDiv = a.parentNode.getElementsByTagName("div")[0];
            if (flag) {
                detailDiv.style.display = "block";
            }
            else
                detailDiv.style.display = "none";
        }
        //重置密码
        function resetPwd() {
            alert("请至少选择一条数据！");
            //document.getElementById("operate_result_info").style.display = "block";
        }
        //删除
        function deleteAdmin() {
            var r = window.confirm("确定要删除此管理员吗？");
            document.getElementById("operate_result_info").style.display = "block";
        }
        //全选
        function selectAdmins(inputObj) {
            var inputArray = document.getElementById("datalist").getElementsByTagName("input");
            for (var i = 1; i < inputArray.length; i++) {
                if (inputArray[i].type == "checkbox") {
                    inputArray[i].checked = inputObj.checked;
                }
            }
        }
    </script>
</head>
<body>
<!--Logo区域开始-->
<div id="header">
    <img src="../images/logo.png" alt="logo" class="left"/>
    <a href="/logout">[退出]</a>
</div>
<!--Logo区域结束-->
<!--导航区域开始-->
<div id="navi">
    <ul id="menu">
        <li><a href="/index" class="index_on"></a></li>
        <li id="lia1"><a href="/role_list" class="role_off"></a></li>
        <li id="lia2"><a href="/admin_list" class="admin_off"></a></li>
        <li id="lia3"><a href="/fee_list" class="fee_off"></a></li>
        <li id="lia4"><a href="/account_list" class="account_off"></a></li>
        <li id="lia5"><a href="/service_list" class="service_off"></a></li>
        <li id="lia6"><a href="/bill_list" class="bill_off"></a></li>
        <li id="lia7"><a href="/report_list" class="report_off"></a></li>
        <li><a href="/userInfo" class="information_off"></a></li>
        <li><a href="/userModifyPwd" class="password_off"></a></li>
    </ul>
</div>
<!--导航区域结束-->
<!--主要区域开始-->
<div id="main">
    <form action="" method="">
        <!--查询-->
        <div class="search_add">
            <div>
                模块：
                <select id="selModules" class="select_search">
                    <option>全部</option>
                    <option>角色管理</option>
                    <option>管理员管理</option>
                    <option>资费管理</option>
                    <option>账务账号</option>
                    <option>业务账号</option>
                    <option>账单管理</option>
                    <option>报表</option>
                </select>
            </div>
            <div>角色：<input type="text" id="role_input" class="text_search width200"/></div>
            <div><input type="button" id="search_btn" value="搜索" class="btn_search"/></div>
            <input type="button" value="密码重置" class="btn_add" onclick="resetPwd();"/>
            <input type="button" value="增加" class="btn_add" onclick="location.href='/admin_add' ; "/>
        </div>
        <!--删除和密码重置的操作提示-->
        <div id="operate_result_info" class="operate_fail">
            <img src="../images/close.png" onclick="this.parentNode.style.display='none';"/>
            <span>删除失败！数据并发错误。</span><!--密码重置失败！数据并发错误。-->
        </div>
        <!--数据区域：用表格展示数据-->
        <div id="data">
            <table id="datalist">
                <tr>
                    <th class="th_select_all">
                        <input type="checkbox" onclick="selectAdmins(this);"/>
                        <span>全选</span>
                    </th>
                    <th>管理员ID</th>
                    <th>姓名</th>
                    <th>登录名</th>
                    <th>电话</th>
                    <th>电子邮件</th>
                    <th>授权日期</th>
                    <th class="width100">拥有角色</th>
                    <th></th>
                </tr>

            </table>
        </div>
        <!--分页-->
        <div id="pages">

        </div>
    </form>
</div>
<!--主要区域结束-->
<div id="footer">
    <p>[源自北美的技术，最优秀的师资，最真实的企业环境，最适用的实战项目]</p>
    <span>版权所有(C)云科技有限公司 </span>
</div>
</body>
<script src="/js/jquery-3.2.1.js"></script>
<script>
    show();

    adminpage();
    function show() {
        $.ajax({
            url: "/selectAllModules",
            type: "post",
            success: function (result) {

                if (result.indexOf("角色管理") == -1) {
                    document.getElementById("lia1").style.display = "none"
                }
                if (result.indexOf("管理员") == -1) {
                    document.getElementById("lia2").style.display = "none"
                }
                if (result.indexOf("资费管理") == -1) {
                    document.getElementById("lia3").style.display = "none"
                }
                if (result.indexOf("账务账号") == -1) {
                    document.getElementById("lia4").style.display = "none"
                }
                if (result.indexOf("业务账号") == -1) {
                    document.getElementById("lia5").style.display = "none"
                }
                if (result.indexOf("账单管理") == -1) {
                    document.getElementById("lia6").style.display = "none"
                }
                if (result.indexOf("报表") == -1) {
                    document.getElementById("lia7").style.display = "none"
                }


            }

        });
    }


    function adminpage() {
        $.ajax({
            url: "/adminpage",
            method: "post",
            data: {
                pageNum: 1,
                pageSize: 3
            },
            success: function (result) {

                resultData(result);
            }
        });
    }
    function page(pagenum) {
        $.ajax({
            url: "/adminpage",
            type: "post",
            data: {
                pageNum: pagenum,
                pageSize: 3
            },
            success: function (result) {
                resultData(result);
            }
        });
    }

    function tiao(adminid) {
        window.location.href = "/admin_modi?id=" + adminid;
    }
    function setDelState(adminid) {
        $.ajax({
            url: "/deleteRoleByAdminId",
            type: "post",
            data: {
                id:adminid
            },
            success:function (result) {
                window.location.href=result.msg;
            }
        });

    }

    function resultData(result) {
        $("#datalist").html("");
        $("#datalist").append("<tr>" +
                "<th class='th_select_all'><input type='checkbox' onclick='selectAdmins(this);'/><span>全选</span></th>" +
                "<th>管理员ID</th>" +
                "<th >姓名</th>" +
                "<th >登录名</th>" +
                "<th >电话</th>" +
                "<th >电子邮件</th>" +
                "<th >授权日期</th>" +
                "<th class='width100'>拥有角色</th>" +
                "<th ></th>" +
                "</tr>");
        var pagenum = result.pageNum;
        //每页显示几条数据
        var pagesize = result.pageSize;
        var size = result.size;
        var startrow = result.startRow;
        var endrow = result.startRow;
        var total = result.total;
        var pages = result.pages;
        var firstpage = result.firstPage;
        var prepage = result.prePage;
        var nextpage = result.nextPage;
        var lastpage = result.lastPage;
        var isfirstpage = result.isFirstPage;
        var islastpage = result.isLastPage;
        var haspreviouspage = result.hasPreviiousPage;
        var hasnextpage = result.hasNextPage;
        var navigatepages = result.navigatePages;
        var navigatepagenums = result.navigatepageNums;
        var adminList = result.list;

        if (isfirstpage) {
            prepage = firstpage
        }
        if (islastpage) {
            nextpage = lastpage;
        }
        for (var i = 0; i < adminList.length; i++) {
            var adminInfo = adminList[i];
            var adminid = adminInfo.adminId;
            var adminCode = adminInfo.adminCode;
            var adminName = adminInfo.name;
            var telephone = adminInfo.telephone;
            var email = adminInfo.email;
            var enrolldate = adminInfo.enrolldate;
            var roleInfoList = adminInfo.roleInfoList;
            var count = "";
            for (var j = 0; j < roleInfoList.length; j++) {
                var roleInfoBean = roleInfoList[j];
                var name = roleInfoBean.name + " , ";
                count += name;
            }
            var tr = $("<tr></tr>");
            var td = $("<td><input type='checkbox'/></td>");
            var tdid = $("<td></td>").text(adminid);
            var tdCode = $("<td></td>").text(adminName);
            var tdName = $("<td></td>").text(adminCode);
            var tdtele = $("<td></td>").text(telephone);
            var tdemail = $("<td></td>").text(email);
            var tdenrolldate = $("<td></td>").text(enrolldate);
            var name1 = $("<td></td>");
            var aName = $("<a class='summary' onmouseover='showDetail(true,this);' onmouseout='showDetail(false,this);'></a>").text(name);
            var divName = $("<div class='detail_info'></div>").text(count);
            name1.append(aName).append(divName);
//            var a1 = $("<a href='/admin_modi?id=" + adminid + "'>修改 x</a>");
//            var a2 = $("<a href='/deleteRoleByAdminId?id=" + adminid + "' > 删除</a>");
            var a1 = $("<input type='button' value='修改' class='btn_modify'  onclick='tiao(" + adminid + ")'/>");
            var a2= $("<input type='button' value='删除' class='btn_delete'  onclick='setDelState(" + adminid + ")'/>");
            var changeBtn = $("<td></td>");
            changeBtn.append(a1).append(a2);
            tr.append(td).append(tdid).append(tdCode).append(tdName).append(tdtele).append(tdemail).append(tdenrolldate).append(name1).append(changeBtn);
            $("#datalist").append(tr)

        }
        $("#pages").html("");
        var a11 = $("<a href='javascript:void(0)' onclick='page(" + firstpage + ")'></a>").text("首页");
        var a12 = $("<a href='javascript:void(0)' onclick='page(" + prepage + ")'></a>").text("上一页");
        $("#pages").append(a11).append(a12);
        for (var k = 1; k <= lastpage; k++) {
            $("#pages").append($("<a href='javascript:void(0)' onclick='page(" + k + ")' >" + k + "</a>"));
        }
        var a13 = $("<a href='javascript:void(0)' onclick='page(" + nextpage + ")'></a>").text("下一页");
        var a14 = $("<a href='javascript:void(0)' onclick='page(" + lastpage + ")'></a>").text("尾页");
        $("#pages").append(a13).append(a14);
    }

    $("#search_btn").click(function () {
        if ($("#role_input").val() == "") {
            alert("不能为空")
        }else {
            adminSearchpage();
        }
    });

    function adminSearchpage() {
        $.ajax({
            url: "/adminSearch",
            method: "post",
            data: {
                pageNum: 1,
                pageSize: 3,
                name: $("#role_input").val()
            },
            success: function (result) {
                console.log(result);
                searchresultData(result);
            }
        });
    }

    function searchpage(pagenum) {
        $.ajax({
            url: "/adminSearch",
            type: "post",
            data: {
                pageNum: pagenum,
                pageSize: 3,
                name: $("#role_input").val()
            },
            success: function (result) {
                searchresultData(result);
            }
        });
    }

    function searchresultData(result) {
        $("#datalist").html("");
        $("#datalist").append("<tr>" +
                "<th class='th_select_all'><input type='checkbox' onclick='selectAdmins(this);'/><span>全选</span></th>" +
                "<th>管理员ID</th>" +
                "<th >姓名</th>" +
                "<th >登录名</th>" +
                "<th >电话</th>" +
                "<th >电子邮件</th>" +
                "<th >授权日期</th>" +
                "<th class='width100'>拥有角色</th>" +
                "<th ></th>" +
                "</tr>");
        var pagenum = result.pageNum;
        //每页显示几条数据
        var pagesize = result.pageSize;
        var size = result.size;
        var startrow = result.startRow;
        var endrow = result.startRow;
        var total = result.total;
        var pages = result.pages;
        var firstpage = result.firstPage;
        var prepage = result.prePage;
        var nextpage = result.nextPage;
        var lastpage = result.lastPage;
        var isfirstpage = result.isFirstPage;
        var islastpage = result.isLastPage;
        var haspreviouspage = result.hasPreviiousPage;
        var hasnextpage = result.hasNextPage;
        var navigatepages = result.navigatePages;
        var navigatepagenums = result.navigatepageNums;
        var adminList = result.list;

        if (isfirstpage) {
            prepage = firstpage
        }
        if (islastpage) {
            nextpage = lastpage;
        }
        for (var i = 0; i < adminList.length; i++) {
            var adminInfo = adminList[i];
            var adminid = adminInfo.adminId;
            var adminCode = adminInfo.adminCode;
            var adminName = adminInfo.name;
            var telephone = adminInfo.telephone;
            var email = adminInfo.email;
            var enrolldate = adminInfo.enrolldate;
            var roleInfoList = adminInfo.roleInfoList;
            var count = "";
            for (var j = 0; j < roleInfoList.length; j++) {
                var roleInfoBean = roleInfoList[j];
                var name = roleInfoBean.name + " , ";
                count += name;
            }
            var tr = $("<tr></tr>");
            var td = $("<td><input type='checkbox'/></td>");
            var tdid = $("<td></td>").text(adminid);
            var tdCode = $("<td></td>").text(adminName);
            var tdName = $("<td></td>").text(adminCode);
            var tdtele = $("<td></td>").text(telephone);
            var tdemail = $("<td></td>").text(email);
            var tdenrolldate = $("<td></td>").text(enrolldate);
            var name1 = $("<td></td>");
            var aName = $("<a class='summary' onmouseover='showDetail(true,this);' onmouseout='showDetail(false,this);'></a>").text(name);
            var divName = $("<div class='detail_info'></div>").text(count);
            name1.append(aName).append(divName);
//            var a1 = $("<a href='/admin_modi?id=" + adminid + "'>修改 x</a>");
//            var a2 = $("<a href='/deleteRoleByAdminId?id=" + adminid + "' > 删除</a>");
            var a1 = $("<input type='button' value='修改' class='btn_modify'  onclick='tiao(" + adminid + ")'/>");
            var a2= $("<input type='button' value='删除' class='btn_delete'  onclick='setDelState(" + adminid + ")'/>");
            var changeBtn = $("<td></td>");
            changeBtn.append(a1).append(a2);
            tr.append(td).append(tdid).append(tdCode).append(tdName).append(tdtele).append(tdemail).append(tdenrolldate).append(name1).append(changeBtn);
            $("#datalist").append(tr)

        }
        $("#pages").html("");
        var a11 = $("<a href='javascript:void(0)' onclick='searchpage(" + firstpage + ")'></a>").text("首页");
        var a12 = $("<a href='javascript:void(0)' onclick='searchpage(" + prepage + ")'></a>").text("上一页");
        $("#pages").append(a11).append(a12);
        for (var k = 1; k <= lastpage; k++) {
            $("#pages").append($("<a href='javascript:void(0)' onclick='searchpage(" + k + ")' >" + k + "</a>"));
        }
        var a13 = $("<a href='javascript:void(0)' onclick='searchpage(" + nextpage + ")'></a>").text("下一页");
        var a14 = $("<a href='javascript:void(0)' onclick='searchpage(" + lastpage + ")'></a>").text("尾页");
        $("#pages").append(a13).append(a14);
    }
</script>
</html>
